package com.xiaoshun.domain.controller;

import com.xiaoshun.common.response.DaoCaoResult;
import com.xiaoshun.domain.entity.UmsSysUser;
import com.xiaoshun.domain.service.IUmsSysUserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("ums/sysuser")
public class UmsSysUserController {
    private final IUmsSysUserService sysUserService;

    public UmsSysUserController(IUmsSysUserService sysUserService) {
        this.sysUserService = sysUserService;
    }
    /**
     * 新增用户
     */
    @PostMapping
    public DaoCaoResult addSysUser(@RequestBody UmsSysUser umsSysUser) {
        boolean flag = sysUserService.save(umsSysUser);
        if (flag) {
            return DaoCaoResult.success();
        }
        return DaoCaoResult.error();
    }

    /**
     * 查询用户列表
     */
    @GetMapping
    public DaoCaoResult searchList(){
        List<UmsSysUser> users = sysUserService.list();
        users.forEach(System.out::println);
        return DaoCaoResult.success().put("users", users);
    }
}
